unit smSceneRender;

interface

uses
  SysUtils, smConst;

type
  TSceneRenderer = class(TObject)
  protected
    procedure PrintSceneName(
      const Scene: Pointer; const ASystem: Boolean = False
    ); inline;
    procedure DrawSceneFading(const Scene: Pointer); inline;

  public
    procedure DrawSceneNone(const Scene: Pointer);
    procedure DrawSceneIntro(const Scene: Pointer);
    procedure DrawSceneMenu(const Scene: Pointer);
    procedure DrawSceneLevel(const Scene: Pointer);
    procedure DrawSceneOutro(const Scene: Pointer);
  end;

implementation

uses
  smMain, smGUI, smSceneManager, smPlayer, smWorld;

{ TSceneRenderer }

procedure TSceneRenderer.DrawSceneNone(const Scene: Pointer);
begin
  DrawSceneFading(Scene);
  PrintSceneName(Scene, True);
end;

procedure TSceneRenderer.DrawSceneIntro(const Scene: Pointer);
begin

end;

procedure TSceneRenderer.DrawSceneMenu(const Scene: Pointer);
begin
  GUIManager.Render();

  DrawSceneFading(Scene);
  PrintSceneName(Scene);
end;

procedure TSceneRenderer.DrawSceneLevel(const Scene: Pointer);
begin
  if Player.Ready then
    Game.FontSystem.Print(
      500, 10, $FF8080FF, Player.Name
    );

  if Player.World.State >= wsLoading then
  begin
    if Player.World.State = wsReady then
      GUIManager.Render();
    Player.World.Render();
  end;

  DrawSceneFading(Scene);
  PrintSceneName(Scene);
end;

procedure TSceneRenderer.DrawSceneOutro(const Scene: Pointer);
begin

end;

procedure TSceneRenderer.PrintSceneName;
begin
  with TScene(Scene) do
    if ASystem then
      Game.FontSystem.Print(10, 30, $FF80FF80, SystemName)
    else
      Game.FontSystem.Print(10, 30, $FF80FF80, DisplayName);
end;

procedure TSceneRenderer.DrawSceneFading(const Scene: Pointer);
begin
  with TScene(Scene) do
  begin
    if State in [ssLoading, ssUnloading] then
      Game.Prim2D.DrawRect(
        0, 0, ScreenWidth, ScreenHeight,
        Byte(Trunc(Alpha * $FE) + 1) shl 24 or $010101
      );
  end;
end;

end.
